<!--
  * BIP运算单行
  *
  * @Author:    AKITA
  * @Date:      2025-08-13 23:51:27
  * @Copyright  AKITA
-->
<template>
  <a-drawer title="打印" width="100%" :open="visibleFlag" @close="onClose" :maskClosable="false" :destroyOnClose="true">
    <iframe width="100%" height="100%" :src="data.src"></iframe>

  </a-drawer>
</template>
<script setup>
  import { reactive, ref, nextTick } from 'vue';

  import { message } from 'ant-design-vue';
  import { SmartLoading } from '/@/components/framework/smart-loading';
  import { bipordbApi } from '/@/api/business/erp/bipord-api';
  import { smartSentry } from '/@/lib/smart-sentry';

  // ------------------------ 事件 ------------------------

  const emits = defineEmits(['reloadList']);

  // ------------------------ 显示与隐藏 ------------------------
  // 是否显示
  const visibleFlag = ref(false);

  const data = reactive({
    src: '',
  });

  function show(item) {
    data.src = item;
    visibleFlag.value = true;
  }

  function onClose() {
    Object.assign(form, formDefault);
    visibleFlag.value = false;
  }

  // ------------------------ 表单 ------------------------

  // 组件ref
  const formRef = ref();

  const formDefault = {
    id: undefined, //电键
    lineNum: undefined, //行号
    baseId: undefined, //基础电键
    baseLineNum: undefined, //基础行号
    lineStatus: undefined, //行状态
    freeTxt: undefined, //行备注
    itemId: undefined, //物料编码
    itemName: undefined, //物料名称
    specs: undefined, //规格
    unit: undefined, //单位
    onOrderQty: 0, //在途数量
    invQty: 0, //库存数量
    reqDate: undefined, //需求日期
    addQty: 0,
    reqQty: 0,
    source: undefined,
  };

  let form = reactive({ ...formDefault });

  const rules = {};

  // 点击确定，验证表单
  async function onSubmit() {
    try {
      await formRef.value.validateFields();
      save();
    } catch (err) {
      message.error('参数验证错误，请仔细填写表单数据!');
    }
  }

  // 新建、编辑API
  async function save() {
    SmartLoading.show();
    try {
      if (form.id) {
        await bipordbApi.update(form);
      } else {
        await bipordbApi.add(form);
      }
      message.success('操作成功');
      emits('reloadList');
      onClose();
    } catch (err) {
      smartSentry.captureError(err);
    } finally {
      SmartLoading.hide();
    }
  }

  defineExpose({
    show,
  });
</script>
